package com.zy.nft_system.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zy.nft_system.domain.Announcement;
import com.zy.nft_system.domain.Carouselmap;
import com.zy.nft_system.domain.Result;
import com.zy.nft_system.domain.dto.CarouselmapDto;
import com.zy.nft_system.service.CarouselmapService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 这是那头猪？
 * @version 1.0
 * @description: TODO
 * @date 2022/12/16 15:24
 */
@RestController
@RequestMapping("/Carouselmap")
@Slf4j
public class CarouselmapController {

    @Autowired
    CarouselmapService carouselmapService;

    @GetMapping("/queryCarouselmapList")
    public Result queryCarouselmapList(){
        log.info("正在查询轮播图img");
        List<Carouselmap> list = carouselmapService.list();
        log.info("查询成功");
        return Result.success("查询成功", list);
    }

    @PostMapping("/updateCarouselmap")
    public Result updateCarouselmap(@RequestBody CarouselmapDto carouselmaps){
        log.info("正在修改轮播图");
        List<Carouselmap> carouselmaps1 = carouselmaps.getCarouselmaps();
        for (Carouselmap c: carouselmaps1) {
            if (! carouselmapService.update(c, new QueryWrapper<Carouselmap>().eq("id", c.getId()))) {
                log.info("修改失败");
                return Result.error("修改失败");
            }
        }
        log.info("修改成功");
        return Result.success("修改成功", null);
    }
}
